package com.vnp.vchat.net;

import org.json.JSONException;

import com.telpoo.frame.net.BaseNetSupportBeta;
import com.telpoo.frame.object.BaseObject;
import com.telpoo.frame.utils.JsonSupport;
import com.vnp.vchat.task.NetData;

public class NetSupport {

	public static NetData vgid2chatid(String userId, String senderId, String hash) {
		NetData data = new NetData();
		String parram = "use_id=" + senderId + "&send_id=" + userId + "&hash=" + hash;
		String url = "http://vchat.vn/service/gdetail_chat.php";
		String res = BaseNetSupportBeta.getInstance().method_POST(url, parram);

		if (res == null) {
			data.status = NetData.STATUS_NO_NETWORK;
			return data;
		}

		try {
			BaseObject oj = JsonSupport.jsonObject2BaseOj(res);

			String err = oj.get("error");
			if (!err.equals("")) { // khong lay duoc id
				data.status = 1;
				data.msg = err;
				return data;
			}

			data.status = 0;
			data.data = oj.get("id");
			return data;

		} catch (JSONException e) {
			data.status = NetData.STATUS_ERROR_SERVER;
			return data;
		}

	}

}
